<template>
  <div class="teacherList">
    <h1>教学计划表单</h1>
    <el-form
      :model="queryMap"
      ref="queryParams"
      label-width="100px"
      style="padding: 5px"
      :rules="rules"
      label-position="top"
    >
      <!-- <h3 style="text-align: center; margin-bottom: 20px">课程信息</h3> -->
      <el-form-item label="课程名称" prop="courseName" >
        <el-select
          v-model="queryMap.courseName"
          style="width: 100%"
          :disabled="true"
          placeholder="请选择"
        >
          <el-option
            v-for="(item, index) in options"
            :key="index"
            :label="item.name"
            :value="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学时数" prop="hours">
        <el-input v-model="queryMap.hours" type="number" min="0"></el-input>
      </el-form-item>
      <el-form-item label="教材或教案" prop="textbook">
        <el-input v-model="queryMap.textbook"></el-input>
      </el-form-item>
      <!-- <h3 style="text-align: center; margin-bottom: 20px">培训讲课教师信息</h3> -->
      <el-form-item label="姓名" prop="teacherName">
        <el-input v-model="queryMap.teacherName"></el-input>
      </el-form-item>
      <el-form-item label="工作单位" prop="teacherWorkplace">
        <el-input v-model="queryMap.teacherWorkplace"></el-input>
      </el-form-item>
      <el-form-item label="毕业院校" prop="teacherGraduatingSchool">
        <el-input v-model="queryMap.teacherGraduatingSchool"></el-input>
      </el-form-item>
      <el-form-item label="所学专业" prop="teacherMajor">
        <el-input v-model="queryMap.teacherMajor"></el-input>
      </el-form-item>
      <el-form-item label="所教专业" prop="teacherTeachingMajor">
        <el-input v-model="queryMap.teacherTeachingMajor"></el-input>
      </el-form-item>
      <el-form-item label="职称" prop="teacherTitle">
        <el-input v-model="queryMap.teacherTitle"></el-input>
      </el-form-item>
      <el-form-item label="签字" prop="teacherSignature">
        <signature v-model="queryMap.teacherSignature"></signature>
      </el-form-item>
      <el-form-item style="text-align: center">
        <el-button type="primary" @click="addCourse">提交</el-button>
        <el-button @click="goBack">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {
  teachingPlanExecutionGet,
  teachingPlanExecutionSave,
  teachingPlanExecutionUpdate,
} from "@/api/OneStageOneGear/OneStageOneGear.js";
import { fetchOptions } from "@/api/signIn/index.js";
export default {
  name: "TeacherUpdate",
  data() {
    return {
      options: [],
      queryMap: {
        courseName: this.$route.query.courseName,
        hours: 0,
        id: "",
        teacherGraduatingSchool: "",
        teacherMajor: "",
        teacherName: "",
        teacherSignature: "",
        teacherTeachingMajor: "",
        teacherTitle: "",
        teacherWorkplace: "",
        textbook: "",
        trainingClassInfoId: '',
      },
      rules: {
        courseName: [
          { required: true, message: "请输入课程名称", trigger: "blur" },
        ],
        hours: [{ required: true, message: "请输入课时", trigger: "blur" }],
        teacherGraduatingSchool: [
          { required: true, message: "请输入毕业院校", trigger: "blur" },
        ],
        teacherMajor: [
          { required: true, message: "请输入所学专业", trigger: "blur" },
        ],
        teacherName: [
          { required: true, message: "请输入姓名", trigger: "blur" },
        ],
        teacherTeachingMajor: [
          { required: true, message: "请输入所教专业", trigger: "blur" },
        ],
        teacherTitle: [
          { required: true, message: "请输入职称", trigger: "blur" },
        ],
        teacherWorkplace: [
          { required: true, message: "请输入工作单位", trigger: "blur" },
        ],
        textbook: [
          { required: true, message: "请输入教材或教案", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    async getOptions() {
      let res = await fetchOptions({
        id: this.$route.query.trainingClassInfoId,
      });
      console.log(res, "培训课程");
      if (res.code == 200) {
        this.options = res.data;
      }
    },
    //新增/修改
    async addCourse() {
      this.$refs.queryParams.validate(async (valid) => {
        if (valid) {
          let res;
          if (this.queryMap.id) {
            res = await teachingPlanExecutionUpdate(this.queryMap);
          } else {
            res = await teachingPlanExecutionSave(this.queryMap);
          }
          if (res.code == 200) {
            this.$message({ message: "修改成功", type: "success" });
            setTimeout(() => {
              this.$router.go(-1);
            }, 1000);
          }
        }
      });
    },
    goBack() {
      this.$router.go(-1);
    },
  },
  async created() {
    console.log(this.$route.query);
    this.queryMap.id = this.$route.query.id;
    this.queryMap.trainingClassInfoId = this.$route.query.trainingClassInfoId;
    this.queryMap.courseName = this.$route.query.courseName;
    this.queryMap.trainingClassScheduleId = this.$route.query.trainingClassScheduleId;
    // this.getOptions();
    if (this.$route.query.id) {
        let res = await teachingPlanExecutionGet(this.$route.query.id);
        if (res.code == 200) {
          this.queryMap = res.data;
        }
      }
  },
};
</script>
<style lang="less" scoped>
.teacherList {
  padding: 10px;
  height: 100%;
  background: rgba(251 250 250);
  h1 {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
  }
  h3{
    font-size: 18px;
  }
}
</style>
